/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import model.*;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "intermb")
@SessionScoped
public class InterViewManagedBean {
    @EJB
    private CvFacade cvFacade;
    @EJB
    private EmployeeFacade employeeFacade;
    
    private String CvID;
    private String EmployeeID;
private String message = new String();

    public String getMessage() {
        return message;
    }
    public String getCvID() {
        return CvID;
    }

    public void setCvID(String CvID) {
        this.CvID = CvID;
    }

    public String getEmployeeID() {
        return EmployeeID;
    }

    public void setEmployeeID(String EmployeeID) {
        this.EmployeeID = EmployeeID;
    }

    public CvFacade getCvFacade() {
        return cvFacade;
    }

    public void setCvFacade(CvFacade cvFacade) {
        this.cvFacade = cvFacade;
    }

    public EmployeeFacade getEmployeeFacade() {
        return employeeFacade;
    }

    public void setEmployeeFacade(EmployeeFacade employeeFacade) {
        this.employeeFacade = employeeFacade;
    }
    @EJB
    private InterviewFacade interviewFacade;
    
    private Interview inter = new Interview();
    
    public Interview getInter() {
        return inter;
    }

    public void setInter(Interview inter) {
        this.inter = inter;
    }

    public InterViewManagedBean() {
    }

    public InterviewFacade getInterviewFacade() {
        return interviewFacade;
    }

    public void setInterviewFacade(InterviewFacade interviewFacade) {
        this.interviewFacade = interviewFacade;
    }

   
    
       public List<Interview> interList() {
        return this.interviewFacade.findAll();
    }
       public List<Cv> cvlistin(){
          return this.cvFacade.findAll();
       }
        public List<Employee> emplistin(){
          return this.employeeFacade.findAll();
       }
        public String addInter() {
            String page ="";
            int li = interList().size();
            for (int i = 0; i < li; i++) {
                if (interList().get(i).getInterviewID().equals(this.inter)){
                    page="Create";
                }else
                {
                    this.inter = this.inter;
                }
            }
            if(this.inter.getEndedTime().getDate()-this.inter.getStartedTime().getDate() > 0){
                this.inter.setEmployeeID(this.employeeFacade.find(this.EmployeeID));
                        this.inter.setCvid(this.cvFacade.find(this.CvID));
                        this.interviewFacade.create(inter);
                        page ="List";
            }
            else{
                
                 page="Create";
            }
                         
                
            
        return page;
    }

    public String editInter() {
        String page ="";
            int li = interList().size();
            for (int i = 0; i < li; i++) {
                if (interList().get(i).getInterviewID().equals(this.inter)){
                    page="Edit";
                }else
                {
                    this.inter = this.inter;
                }
            }
            if(this.inter.getEndedTime().getDate()-this.inter.getStartedTime().getDate() > 0){
                this.inter.setEmployeeID(this.employeeFacade.find(this.EmployeeID));
                        this.inter.setCvid(this.cvFacade.find(this.CvID));
                        this.interviewFacade.edit(inter);
                        page ="List";
            }
            else{
                
                 page="Edit";
            }
                         
                
            
        return page;
        
    }

    public String deleteInter(Interview in) {
        String page = "";
        try {
             this.interviewFacade.remove(in);
        page= "List";
        } catch (Exception e) {
            this.message ="Delete not found";
        }
        return page;
    }

    public String interEdit(Interview in) {
        this.inter = in;
        return "Edit";
    }

    public String interView(Interview in) {
        this.inter = in;
        return "View";
    }
       
   
}
